{extend name="base"}
{block name="main"}
<div id="app" v-cloak>
    <el-row class="ws-quote">
        <el-col :span="24" >
            微手设置
        </el-col>
    </el-row>
    <el-table :data="baseData" border stripe header-row-style="">
        <el-table-column label="配置项" width="260px" prop="name" align="center"></el-table-column>
        <el-table-column label="参数值">
            <template slot-scope="scope">

                <el-input v-model="scope.row.value" :placeholder="scope.row.remark" v-if="scope.row.type==='input'"></el-input>

                <el-input-number v-model="scope.row.value" :placeholder="scope.row.remark" :min="0" :label="scope.row.remark" v-if="scope.row.type==='number'"></el-input-number>

                <input type="file" name="scope.row.field" @change="appUploads($event,scope.row)" v-if="scope.row.type==='app_uploads'">

                <el-switch v-model="scope.row.value" v-if="scope.row.type==='switch'"></el-switch>
            </template>
        </el-table-column>
        <el-table-column label="说明" prop="remark" align="center"></el-table-column>
    </el-table>
    <el-row class="p_y20">
        <el-col :offset="6" :span="8">
            <el-button type="primary" @click="_wspost('{:url('edit')}',{data:baseData})">更新配置</el-button>
        </el-col>
        
    </el-row>
</div>
{/block}

<!--------------------------分割线------------------------>
<!--------------------------分割线------------------------>
<!--------------------------分割线------------------------>

{block name="vue"}
<script>
var app=new Vue({
    el:'#app',
    mixins:[wsMixins],
    data:{
        list:{$list->toJson()|raw},
        baseData:[
            // 站点配置
            {field:'device_max',name:'微手登录设备限制',type:'number',value:'',remark:'微手登录设备限制，0为无限制'},
            {field:'week_standard',name:'微手周奖励达标金额',type:'input',value:'',remark:'微手周奖励达标金额'},
            {field:'week_bonus',name:'微手周达标奖励金',type:'input',value:'',remark:'微手周达标奖励金'},
            {field:'agent_ratio',name:'微手代理商奖金奖比例',type:'input',value:'',remark:'微手代理商奖金奖比例'},
            {field:'card_coin',name:'发布名片金币',type:'input',value:'',remark:'发布名片需消耗的金币'},
            {field:'card_max',name:'最大名片数',type:'input',value:'',remark:'每个用户最大名片拥有数'},
            // {field:'card_nums',name:'普通用户每日可发名片数',type:'input',value:'',remark:'普通用户每日可发名片数'},
            // {field:'card_vipnums',name:'VIP每日可发名片数',type:'input',value:'',remark:'VIP每日可发名片数'},
            
            {field:'article_coin',name:'发布产品金币',type:'input',value:'',remark:'发布产品需消耗的金币'},
            {field:'vip_article_coin',name:'VIP发布产品金币',type:'input',value:'',remark:'VIP发布产品需消耗的金币'},
            {field:'vip_first_article_coin',name:'VIP首次发布产品金币',type:'input',value:'',remark:'VIP首次发布产品需消耗的金币'},
            {field:'article_nums',name:'每日可发产品数',type:'input',value:'',remark:'每日可发产品数'},
            {field:'article_counts',name:'普通用户可拥有产品数量',type:'input',value:'',remark:'普通用户最多可拥有产品数量'},
            {field:'article_vip_counts_inc',name:'VIP可拥有产品增量',type:'input',value:'',remark:'VIP可拥有产品增量(VIP级别+增量+普通会员拥有数=VIP最多可拥有产品数量)'},
            

            //米客小蜜配置
            {field:'weishou_version',name:'微手版本名',type:'input',value:'1',remark:'微手版本名'},
            {field:'weishou_version2',name:'微手版本号',type:'input',value:'1',remark:'微手版本号'},
            {field:'weishou_app',name:'微手App',type:'app_uploads',value:'',remark:'微手App'},
        ]
    },
    created(){
        this.init();
    },
    methods:{
        init(){
            this.baseData.forEach(item=>{
                this.list.forEach(v=>{
                    if(v.field===item.field){
                        item.id=v.id;
                        if(v.type==='switch'){
                            // 字符串转换
                            v.value=v.value==='true';
                        }
                        item.value=v.value;
                    }
                })
            });
        },
        // APP上传
        appUploads(e,row){
            let file=e.target.files[0];
            let formData=new FormData();
            formData.append('id',row.id);
            formData.append('file',file); // 'file' 可变 相当于 input 表单的name 属性
            formData.append('name',row.field);
            this.jqUpload("{:url('appUploads')}",formData,res=>{
                console.log(res);
            });
        },
    }
});
</script>
{/block}